home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / Papers / aSEPiA example source / Application / CScreenSaverApp.cp < prev    next >
Encoding:
Text File  |  1999-06-25  |  4.8 KB  |  197 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    CScreenSaverApp.cp           ©1994-1998 Metrowerks Inc. All rights reserved.
  3. // ===========================================================================
  4. //
  5. //    The Dashboard Starter demo program with SIOUX supported added
  6.  
  7. #include "CScreenSaverApp.h"
  8.  
  9. #include <LApplication.h>
  10. #include <LCaption.h>
  11. #include <LGrowZone.h>
  12. #include <LWindow.h>
  13. #include <UDrawingState.h>
  14. #include <UMemoryMgr.h>
  15. #include <URegistrar.h>
  16.  
  17. #include <LSIOUXAttachment.h>
  18. #include <iostream.h>
  19. #include <LActiveScroller.h>
  20. #include <UAttachments.h>
  21. #include <UReanimator.h>
  22. #include "CPluginTable.h"
  23. #include "CPluginManager.h"
  24. #include "CScreenSaverWindow.h"
  25. #include "UWindows.h"
  26.  
  27. CPluginManager*    gPluginManager = NULL;
  28.  
  29. const ResIDT    WIND_Dashboard    = 200;
  30. const ResIDT    WIND_Screen    = 1000;
  31.  
  32. // ===========================================================================
  33. //        • Main Program
  34. // ===========================================================================
  35.  
  36. void main()
  37. {
  38.                                     // Set Debugging options
  39.     SetDebugThrow_(debugAction_Alert);
  40.     SetDebugSignal_(debugAction_Alert);
  41.  
  42.     InitializeHeap(3);                // Initialize Memory Manager
  43.                                     // Parameter is number of Master Pointer
  44.                                     //   blocks to allocate
  45.     
  46.                                     // Initialize standard Toolbox managers
  47.     UQDGlobals::InitializeToolbox(&qd);
  48.     
  49.     new LGrowZone(20000);            // Install a GrowZone function to catch
  50.                                     //    low memory situations.
  51.                                     //    Parameter is size of reserve memory
  52.                                     //    block to allocated. The first time
  53.                                     //    the GrowZone function is called,
  54.                                     //    there will be at least this much
  55.                                     //    memory left (so you'll have enough
  56.                                     //    memory to alert the user or finish
  57.                                     //    what you are doing).
  58.     
  59.     CScreenSaverApp    theApp;            // Create instance of your Application
  60.     theApp.Run();                    //   class and run it
  61. }
  62.  
  63.  
  64. // ===========================================================================
  65. //        • CScreenSaverApp Class
  66. // ===========================================================================
  67.  
  68. // ---------------------------------------------------------------------------
  69. //        • CScreenSaverApp
  70. // ---------------------------------------------------------------------------
  71. //    Constructor
  72.  
  73. CScreenSaverApp::CScreenSaverApp()
  74. {
  75.         // Register classes for objects created from 'PPob' resources
  76.  
  77.     RegisterClass_(LCaption);
  78.     RegisterClass_(LWindow);
  79.     RegisterClass_(LKeyScrollAttachment);
  80.     RegisterClass_(LColorEraseAttachment);
  81.     RegisterClass_(LStdButton);
  82.     RegisterClass_(CPluginTable);
  83.     RegisterClass_(LActiveScroller);
  84.     RegisterClass_(CScreenSaverWindow);
  85.     
  86.     gPluginManager = new CPluginManager();
  87.     
  88. }
  89.  
  90.  
  91. // ---------------------------------------------------------------------------
  92. //        • ~CScreenSaverApp
  93. // ---------------------------------------------------------------------------
  94. //    Destructor
  95.  
  96. CScreenSaverApp::~CScreenSaverApp()
  97. {
  98.     delete gPluginManager;
  99.  
  100. }
  101.  
  102.  
  103. // ---------------------------------------------------------------------------
  104. //        • Initialize
  105. // ---------------------------------------------------------------------------
  106.  
  107. void
  108. CScreenSaverApp::Initialize()
  109. {
  110.     mDisplayWindow = LWindow::CreateWindow(WIND_Dashboard, this);
  111.     
  112.     UReanimator::LinkListenerToControls( this, mDisplayWindow, WIND_Dashboard );
  113.     
  114.     mDisplayWindow->Show();
  115.     
  116.     AddAttachment(new LSIOUXAttachment);    // *** Use SIOUX Attachment
  117.  
  118.  
  119. }
  120.  
  121. void
  122. CScreenSaverApp::ListenToMessage(
  123.     MessageT    inMessage,
  124.     void*        ioParam)
  125. {
  126.     switch (inMessage) {
  127.     
  128.         case 1500:
  129.         {
  130.             ObeyCommand( 1000 , NULL );
  131.         }
  132.         break;
  133.     }
  134. }
  135.  
  136. // ---------------------------------------------------------------------------
  137. //        • ObeyCommand
  138. // ---------------------------------------------------------------------------
  139. //    Respond to commands
  140.  
  141. Boolean
  142. CScreenSaverApp::ObeyCommand(
  143.     CommandT    inCommand,
  144.     void        *ioParam)
  145. {
  146.     Boolean    cmdHandled = true;
  147.     
  148.     switch (inCommand) {
  149.     
  150.         case 1000:
  151.         {
  152.             LWindow*    ScreenSaverWindow = LWindow::CreateWindow(WIND_Screen, this);
  153.         }
  154.         break;
  155.             
  156.     
  157.         default:
  158.             cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
  159.             break;
  160.     }
  161.     
  162.     return cmdHandled;
  163. }
  164.  
  165.  
  166. // ---------------------------------------------------------------------------
  167. //        • FindCommandStatus
  168. // ---------------------------------------------------------------------------
  169. //    Pass back status of a (menu) command
  170.  
  171. void
  172. CScreenSaverApp::FindCommandStatus(
  173.     CommandT    inCommand,
  174.     Boolean        &outEnabled,
  175.     Boolean        &outUsesMark,
  176.     Char16        &outMark,
  177.     Str255        outName)
  178. {
  179.     switch (inCommand) {
  180.         
  181.         case 1000:
  182.             CPlugin*        plugin = 0;
  183.     
  184.             plugin = gPluginManager->GetCurrentPlugin();
  185.             if ( plugin == 0 ) {
  186.                 outEnabled = false;
  187.             } else {
  188.                 outEnabled = true;
  189.             }
  190.             break;
  191.     
  192.         default:
  193.             LApplication::FindCommandStatus(inCommand, outEnabled, outUsesMark,
  194.                                 outMark, outName);
  195.             break;
  196.     }
  197. }